const {
  getFaceBox,
  createIDPhotoBase64,
  handleBackground,
  setBackground
} = require("./utils.js");
const request = require("request");

// const request = require("request");
module.exports = {
  _before: function () {
    // 通用预处理器
  },
  async getTransparentPictures(base64, px) {
    const newBase64 = await handleBackground(base64);
    if (newBase64.code !== 200)
      return request(newBase64.code, newBase64.message);
    const faseBox = await getFaceBox(newBase64.data);
    if (faseBox.code !== 200) return request(faseBox.code, faseBox.message);
    const transparentBase64 = await createIDPhotoBase64(
      newBase64.data,
      faseBox.data.box,
      {
        width: px[0],
        height: px[1],
      }
    );
    return request(200, transparentBase64);
  },

  async downloadPicture(fileID, background) {
    const newBase64 = await setBackground(fileID, background);
    return request(200, newBase64);
  },
};
